package cn.dev.admin.config;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author LiuRenGang
 * @date 2022/07/05 15:14
 **/
@Configuration
public class RabbitmqConfig {
    //
    @Resource
    private RabbitProperties rabbitProperties;

    @Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitProperties.getHost(), rabbitProperties.getPort());
        //我这里直接在构造方法传入了
        connectionFactory.setHost(rabbitProperties.getHost());
        connectionFactory.setPort(rabbitProperties.getPort());
        connectionFactory.setUsername(rabbitProperties.getUsername());
        connectionFactory.setPassword(rabbitProperties.getPassword());
        connectionFactory.setVirtualHost(rabbitProperties.getVhosts());
        return connectionFactory;
    }


    public static void main(String[] args) {
        //获取当前时间
        LocalDateTime nowTime= LocalDateTime.now();
        //自定义时间
        LocalDateTime endTime = LocalDateTime.of(2022, 07 ,29, 00, 00, 00);
        //比较  如今的时间 比 设定的时间 以前  返回的类型是Boolean类型
        System.out.println(nowTime.isAfter(endTime));
        //比较   如今的时间 比 设定的时间 以后  返回的类型是Boolean类型
        System.out.println(nowTime.isBefore(endTime));
        //比较   如今的时间 和 设定的时候  相等  返回类型是Boolean类型
        System.out.println(nowTime.equals(endTime));
    }

}
